<template>
	<view class="redenvelope">
		<view class="redenvelope-top">
			<view class="redenvelope-top-title">剩余时间</view>
			<view class="redenvelope-top-daoji">{{timenum}}</view>
		</view>
		<view class="redenvelope-redbaobox">
			<redenveloperain :rainHeight="rainHeight" ref="redenveloperain"></redenveloperain>
		</view>
		<redenveloperPopup :rainShow.sync="rainShow"></redenveloperPopup>
	</view>
</template>

<script>
	import redenveloperain from './components/redenveloperain.vue'
	import redenveloperPopup from './components/redenveloperPopup.vue'
	export default {
		components:{
			redenveloperain,
			redenveloperPopup
		},
		data(){
			return{
				rainShow:false,
				rainHeight:0,
				timenum:3,
			}
		},
		onLoad(){
			this.$nextTick(()=>{
				this.getHeight()
			})
			this.countdown()
		},
		methods:{
			//倒计时
			countdown(){
			   let time = setInterval(()=>{
					this.timenum--
					if(this.timenum == 0){
						clearInterval(time)
						this.$refs.redenveloperain.clearsetInte()
						this.rainShow = true
					}
				},1000)
			},
			getHeight(){
				uni.createSelectorQuery().select('.redenvelope-top').boundingClientRect(data => {
					this.rainHeight = data.height * 2
					console.log(this.rainHeight)
				}).exec()

			}
		}
	}
</script>

<style lang="scss" scoped>
	.redenvelope{
		background-image: url('../image/redbg.png');
		width: 750rpx;
		height: 100vh;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		display: flex;
		flex-direction: column;
		
		align-items: center;
		&-top{
			margin-top: 79rpx;
			display: flex;
			align-items: center;
			flex-direction: column;
			&-title{
				font-family: Inter, Inter;
				font-weight: normal;
				font-size: 44rpx;
				color: #FFFFFF;
			}
			&-daoji{
				background-image: url('../image/timebg.png');
				width: 120rpx;
				height: 120rpx;
				background-size: 100% 100%;
				background-repeat: no-repeat;
				text-align: center;
				line-height: 120rpx;
				font-family: Inter, Inter;
				font-weight: 400;
				font-size: 70rpx;
				color: #FFFFFF;
				margin-top: 23rpx;
			}
		}
		&-redbaobox{
			flex: 1;
		}
	}
</style>